#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include<stack>
#include <algorithm>
#include <map>
#include <set>
#include <cstring>
#define endl "\n"
using namespace std;
stack<unsigned long long int> a;
void f(string str)
{

	if (str == "push")
	{
		unsigned long long  x;
		cin >> x;
		a.push(x);	
	}
	else if (str == "pop")
	{
		if (a.empty())
		{
			cout << "Empty" << endl;

		}
		else
			a.pop();
	}
	else if (str == "query")
	{
			if (a.empty())
			{
				cout << "Anguei!" << endl;
			}
			else
				cout << a.top() << endl;
	}
	else
	{
			cout << a.size() << endl;
	}
}

int main()
{
	string str;
	unsigned long long N, n;
	cin >> N;
	while (N--)
	{
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> str;
			f(str);
		}
		while (!a.empty())
		{
			a.pop();
		}
	}
	return 0;
}